package org.apache.commons.graph

import org.apache.commons.graph.bean.VertexPair


/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License.  You may obtain a copy of the License at
*
*   http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied.  See the License for the
* specific language governing permissions and limitations
* under the License.
*/

/**
 * A Graph data structure consists of a finite (and possibly mutable) set of ordered pairs, called edges or
 * arcs, of certain entities called vertex or node. As in mathematics, an edge `(x,y)` is said to
 * point or go from `x` to `y`.
 *
 * @param <V> the Graph vertices type
 * @param <E> the Graph edges type
</E></V> */
interface Graph<V, E> {
    /**
     * Returns true if the edge is contained into the graph
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @param e the edge to be checked
     * @return Returns true if the edge is contained into the graph, false otherwise
     */
    fun containsEdge(e: E): Boolean

    /**
     * Returns true if the vertex is contained into the graph
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @param v the vertex to be checked
     * @return Returns true if the vertex is contained into the graph, false otherwise
     */
    fun containsVertex(v: V): Boolean

    /**
     * Returns all vertices which touch this vertex.
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @param v the vertex which connected vertices have to be returned.
     * @return all vertices which touch this vertex.
     */
    fun getConnectedVertices(v: V): Iterable<V>

    /**
     * The degree (or valency) of a vertex of a [Graph]
     * is the number of edges incident to the vertex.
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @param v the vertex which degree has to be returned.
     * @return the number of edges incident to the vertex.
     */
    fun getDegree(v: V): Int

    /**
     * Returns the edge with vertex source and target.
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @param source the source vertex
     * @param target the target vertex
     * @return the edge with vertex source and target.
     */
    fun getEdge(source: V, target: V): E?

    /**
     * Returns the total set of Edges in the graph.
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @return the total set of Edges in the graph.
     */

    val edges: Iterable<E>

    /**
     * Returns the *order* of a Graph (the number of Vertices);
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @return the *order* of a Graph (the number of Vertices);
     */

    val order: Int

    /**
     * Returns the *size* of a Graph (the number of Edges)
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @return the *size* of a Graph (the number of Edges)
     */
    val size: Int

    /**
     * Returns the total set of Vertices in the graph.
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @return the total set of Vertices in the graph.
     */
    val vertices: Iterable<V>

    /**
     * Return the set of vertex on the input edge (2 for normal edges, > 2 for HyperEdges)
     *
     * **NOTE**: implementors have to take in consideration throwing a [GraphException]
     * if an error occurs while performing that operation.
     *
     * @param e the input edge
     * @return the set of vertex on this Edge.
     */
    fun getVertices(e: E): VertexPair<V>?

    companion object
}


